package com.example.administrator.yuejian_2.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.TrainOrderActivity;
import com.example.administrator.yuejian_2.bean.TrainOrderListBean;
import com.example.administrator.yuejian_2.viewholder.TrainOrderListViewHolder;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/7.
 */

public class TrainOrderListAdapter extends RecyclerView.Adapter {
    private List<TrainOrderListBean> trainorder = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;

    public TrainOrderListAdapter(Context context, List<TrainOrderListBean> trainorder){
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.trainorder.addAll(trainorder);

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_trainorder,parent,false);
        TrainOrderListViewHolder holder = new TrainOrderListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        TrainOrderListViewHolder trainorderholder = (TrainOrderListViewHolder) holder;
        TrainOrderListBean trainorderlist = trainorder.get(position);
        trainorderholder.number.setText(String.valueOf(trainorderlist.getNumber()));

        String price = trainorderlist.getCourse_money();
        int i = trainorderlist.getCount();
        int prices = Integer.parseInt(price);
        int sums = i * prices;
        String s = Integer.toString(sums);
        trainorderholder.sum.setText("总价 :"+ s +"元");
        trainorderholder.train_name.setText("培训名称 :" + trainorderlist.getCourse_name());
        trainorderholder.time.setText("下单时间 :" + trainorderlist.getTime());
        String train_picture = trainorderlist.getCourse_pic();
        if (!train_picture.equals(""))
            Picasso.with(context).
                    load("http://10.0.2.2/yuejian16/Public/clubphoto/"+train_picture)
                    .into(trainorderholder.train_pic);

        final int trainorder_id = trainorderlist.getTrainorder_id();
        trainorderholder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, TrainOrderActivity.class);
                intent.putExtra("trainorder_id",trainorder_id);
                context.startActivity(intent);

            }
        });


    }

    @Override
    public int getItemCount() {
        return trainorder.size();
    }
}
